let obj = { a: 1, b: { c: 2 }, d: [1, 2, 3], e: [{ f: [4, 5, 6] }] };
// let r1 = parse(obj, 'a');
// let r2 = parse(obj, 'b.c');// = 2;
let r3 = parse(obj, 'd[2]');// = 3;
// let r4 = parse(obj, 'e[0].f[0]');// = 4;

// function parse(obj, str) {
//   return new Function('obj', 'return obj.' + str.replace(/\.(\d+)/g, '\[$1\]'))(obj);
// }
function parse(obj, str) {
  str = str.replace(/\[(\d+)\]/g, '.$1');
  arr = str.split('.');
  console.log(arr)
  arr.forEach(function (item) {
    console.log(obj[item])
    obj = obj[item];
    // console.log(obj)
  })
  return obj;
}

// console.log(r2);
